package com.xpqh.ksg.modular.caseInfo.service;

import com.xpqh.ksg.common.persistence.dao.KsgCaseInfoMapper;
import com.xpqh.ksg.common.persistence.model.KsgCaseInfo;
import com.xpqh.ksg.modular.caseInfo.dto.KsgDictListRespDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CaseInfoService {

    @Autowired
    private KsgCaseInfoMapper caseInfoMapper;

    public List<KsgCaseInfo> getCaseList2(String vehicleBrand, String vehicleModel , String productSeries, String search, Integer caseType, String classification,String order,String label,Integer pageNo, Integer pageSize) {
        List<KsgCaseInfo> caseList = caseInfoMapper.getCaseList2(vehicleBrand, vehicleModel, productSeries, search, caseType, classification,order,label,(pageNo - 1) * pageSize, pageSize);
        if (null != caseList) {
            for (KsgCaseInfo sjCaseInfo : caseList) {
                sjCaseInfo.setCoverPicture(sjCaseInfo.getCoverPicture() + "?x-oss-process=style/watermark");
                // 分割字符串并使用Stream处理每个图片链接
                String result = Arrays.stream(sjCaseInfo.getPictureList().split("\\|"))
                        .map(url -> url + "?x-oss-process=style/watermark")
                        .collect(Collectors.joining("|"));
                sjCaseInfo.setPictureList(result);
            }
        }
        return caseList;
    }
    public List<KsgCaseInfo> getCaseList(String vehicleBrand, String vehicleModel, String productName, String productSeries,String search,Integer caseType,Integer kind,String language,String  label,Integer pageNo,Integer pageSize) {
        List<KsgCaseInfo> caseList = caseInfoMapper.getCaseList(vehicleBrand, vehicleModel, productName, productSeries, search, caseType, kind, language, label,(pageNo - 1) * pageSize, pageSize);
        if (null != caseList) {
            for (KsgCaseInfo ksgCaseInfo : caseList) {
                ksgCaseInfo.setCoverPicture(ksgCaseInfo.getCoverPicture() + "?x-oss-process=style/watermark");
                // 分割字符串并使用Stream处理每个图片链接
                String result = Arrays.stream(ksgCaseInfo.getPictureList().split("\\|"))
                        .map(url -> url + "?x-oss-process=style/watermark")
                        .collect(Collectors.joining("|"));
                ksgCaseInfo.setPictureList(result);
            }
        }
        return caseList;
    }
    public KsgCaseInfo getCaseDetails(String caseId) {
        KsgCaseInfo KsgCaseInfo = caseInfoMapper.getCaseDetails(caseId);
        KsgCaseInfo.setCoverPicture(KsgCaseInfo.getCoverPicture() + "?x-oss-process=style/watermark");
        // 分割字符串并使用Stream处理每个图片链接
        String result = Arrays.stream(KsgCaseInfo.getPictureList().split("\\|"))
                .map(url -> url + "?x-oss-process=style/watermark")
                .collect(Collectors.joining("|"));
        KsgCaseInfo.setPictureList(result);
        return KsgCaseInfo;
    }
    public Integer getCaseListCount(String vehicleBrand, String vehicleModel, String productName, String productSeries, String search, Integer caseType, Integer kind,String language) {
        return caseInfoMapper.getCaseListCount(vehicleBrand, vehicleModel, productName, productSeries,search,caseType,kind,language);
    }
    public List<KsgDictListRespDTO> getDictList(String dictType) {
        return caseInfoMapper.getDictList(dictType);
    }
}

